﻿using JZ.JiangSu.Application.Services;
using JZ.JiangSu.IApplication.IServices;
using JZ.JiangSu.IRepository;
using JZ.JiangSu.Model.Domain.ResumeDomain;
using JZ.JiangSu.Model.Domain.UserDomain.Events;
using JZ.JiangSu.Model.Entity;
using JZ.JiangSu.Model.EventBus;
using JZ.JiangSu.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DependencyAttribute = Unity.Attributes.DependencyAttribute;

namespace JZ.JiangSu.Application.Services
{
    public class ResumeService : ApplicationService<Resume>, IResumeService
    {
        [Dependency]
        public new IResumeRepository _repository { get; set; }
        [Dependency]
        public IUserRepository userRepository { get; set; }

        //test id=279098
        public Resume GetResume(int id)
        {
            var resume = _repository.GetEntityById(id);

            //原子性业务操作
            var user=userRepository.GetEntityById(resume.UserID);
            ResumeDomainManager rdm = new ResumeDomainManager();
            rdm.VeiwResume(user, resume);
            //

            //如果有事件通知的话注入事件
            TEventBus.Publish(new ViewResumeEvent()
            {
                User = user
            });
            //

            userRepository.Update(user);
            return resume;
        }

    }
}